<?php
define('FRAMEWORKIDE','1.00');

/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

//carica la lingua se esiste
$lang=lang();

switch($lang){
    case "en":
	define("_ADMIN_PREFERENCE","ADMIN PREFERENCE");
	define("_CHANGE_PREFERENCES","change preferences");
	define("_CHANGE_PASSWORD","Change Password");
	define("_RETYPE_PASSWORD","Retype Password");
	define("_SET_PASSWORD","change password");
	define("_ADMINISTRATION_PRIVILEGE_REQUESTED", "administration privilege requested");
	define("_CHANGE","Change");
	define("_CONTINUA","Continue");
	break;
    default;
	define("_ADMIN_PREFERENCE","ADMIN PREFERENCE");
	define("_CHANGE_PREFERENCES","change preferences");
	define("_CHANGE_PASSWORD","Change Password");
	define("_SET_PASSWORD","change password");
	define("_RETYPE_PASSWORD","Retype Password");
	define("_ADMINISTRATION_PRIVILEGE_REQUESTED", "administration privilege requested");
	define("_CHANGE","Change");
	define("_CONTINUA","Continua");
	break;
}

echo "<p align='left'><img src='applications/$appname/_images/logo.png'/></p>";
echo "<input type='button' value='Clicca per lanciare la richiesta' onClick='esempio3()' />";

if (file_exists("extras/FCKeditor/fckeditor.php")){
  include("extras/FCKeditor/fckeditor.php");
}



?>
<script type='text/javascript'>
var runfile = null;
var myRequest = null;
/*function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}*/

function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  try {
        xmlhttp = new XMLHttpRequest();
  } catch(e) {
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}

function myHandler() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
        e = document.getElementById("objecttreeviewinout");
        e.innerHTML = myRequest.responseText;
    }
}

function esempio3() {
    myRequest = CreateXmlHttpReq(myHandler);
    myRequest.open("GET","applications/_admin/FW-IDE/01_code/popup/yuicolorpicker/prova.php");
    myRequest.send(null);
}
// -------------------------------------------------------------------------------------------------------------- //

function run_program(runfile){
	if( navigator.appName != "Netscape"){
    NewWindow=window.open(runfile,"","' scrollbar='auto', resizable=1,top=0,left=760, fullscreen=yes, width=550, height=550, status=0, toolbar=0, location=yes '");
  }
  else{
    NewWindow=window.open(runfile,"","' scrollbar='auto', resizable=1,top=0,left=800, fullscreen=yes, width=550, height=550, status=0, toolbar=0, location=yes '");
  }
	NewWindow.creator=self;
}

// -------------------------------------------------------------------------------------------------------------- //

function spazio (){
    if(document.getElementById('left').style.display !='none'){
	document.getElementById('left').style.display='none';
	document.getElementById('right').style.display='none';
	document.getElementById('center').style.marginLeft='0';
	document.getElementById('center').style.marginRight='0';
	document.getElementById('top').style.display='none';
	document.getElementById('bottom').style.display='none';
    }
    else{
	document.getElementById('left').style.display='inline';
	document.getElementById('right').style.display='inline';
	document.getElementById('center').style.marginLeft=document.getElementById('left').style.width;
	document.getElementById('center').style.marginRight=document.getElementById('right').style.width;
	document.getElementById('top').style.display='inline';
	document.getElementById('bottom').style.display='inline';
    }
}
// -------------------------------------------------------------------------------------------------------------- //
function toolbar_inout (){
    if(document.getElementById('toolbar').style.display !='none'){
    document.getElementById('toolbar').style.display='none';
    }
    else{
    document.getElementById('toolbar').style.display='inline';
    }
}
// -------------------------------------------------------------------------------------------------------------- //
//igrandisce al massimo l'area applicazione
function inout (){
    if(document.getElementById('treeboxbox_tree').style.display !='none'){
    document.getElementById('treebox').style.display='none';
    document.getElementById('treeboxbox_tree').style.display='none';
    document.getElementById('inspector').style.display='none';
    document.getElementById('objectinspector').style.display='none';
    document.getElementById('objecttreeviewinout').style.display='none';
    document.getElementById("objecttreeview").style.display='none';
    }
    else{
    document.getElementById('treeboxbox_tree').style.display='inline';
    document.getElementById('treebox').style.display='inline';
    document.getElementById('inspector').style.display='none';
    document.getElementById('objectinspector').style.display='none';
    document.getElementById('objecttreeviewinout').style.display='none';
    document.getElementById("objecttreeview").style.display='none';
    }
}
// -------------------------------------------------------------------------------------------------------------- //
//igrandisce al massimo l'area applicazione
function inspectorinout (){
    if(document.getElementById('inspector').style.display !='none'){
    document.getElementById('treeboxbox_tree').style.display='none';
    document.getElementById('treebox').style.display='none';
    document.getElementById('inspector').style.display='none';
    document.getElementById('objectinspector').style.display='none';
    }
    else{
    document.getElementById('treeboxbox_tree').style.display='none';
    document.getElementById('treebox').style.display='none';
    document.getElementById('inspector').style.display='inline';
    document.getElementById('objectinspector').style.display='inline';
    }
}
// -------------------------------------------------------------------------------------------------------------- //
//igrandisce al massimo l'area applicazione
function objecttreeviewinout (){
    if(document.getElementById('objecttreeviewinout').style.display !='none'){
    document.getElementById('treeboxbox_tree').style.display='none';
    document.getElementById('treebox').style.display='none';
    document.getElementById('objecttreeviewinout').style.display='none';
    document.getElementById("objecttreeview").style.display='none';
    }
    else{
    document.getElementById('treeboxbox_tree').style.display='none';
    document.getElementById('treebox').style.display='none';
    document.getElementById('objecttreeviewinout').style.display='inline';
    document.getElementById("objecttreeview").style.display='inline';
    }
}
// -------------------------------------------------------------------------------------------------------------- //
function openPopUp(name,component,theme){
	if( navigator.appName != "Netscape"){
    NewWindow=window.open("<?="$path/$appname";?>/popup/component/"+component+"/"+name+".php?theme="+theme,"","' scrollbar='auto', resizable=1,top=0,left=760, width=250, height=750, status=0, toolbar=0 '");
  }
  else{
    NewWindow=window.open("<?="$path/$appname";?>/popup/component/"+component+"/"+name+".php?theme="+theme,"","' scrollbar='auto', resizable=1,top=0,left=800, width=260, height=580, status=0, toolbar=0 '");
  }
	NewWindow.creator=self;
}
// -------------------------------------------------------------------------------------------------------------- //
</script>

<script type="text/javascript" src="js/tabs/tabpane.js"></script>
<link type="text/css" rel="StyleSheet" href="js/tabs/tabpane.css" />

<div class='table'>
  <p>
  <fieldset id='toolbar' >
  <legend> COMPONENT TOOLBAR </legend>
  <br>


<div class="tab-pane" id="tab-pane-1">

   <div class="tab-page">

      <h2 class="tab">Standard</h2>

    <?php
      //popup icons link autoload
      $component="standard";
      $i=0;
      $fd=opendir("$path/$appname/popup/component/standard/");
      while (false !== ($nf= readdir($fd))){
          if (substr($nf,-4)==".php" && substr($nf, -10) !="dialog.php")
            $popups[$i++]=$nf;
      }
      closedir($fd);
      if ($i>0){
	    sort($popups);
	    foreach($popups as $popup){
		$popup=substr($popup,0,-4);
		echo"<acronym title='".substr($popup,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/standard/$popup.png' border=0 onClick=\"openPopUp('$popup','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>
   </div>

   <div class="tab-page">
      <h2 class="tab">Additional</h2>
    <?php
      //popup icons link autoload
      $component="additional";
      $i=0;
      $fd_additional=opendir("$path/$appname/popup/component/additional/");
      while (false !== ($nf_additional= readdir($fd_additional))){
          if (substr($nf_additional, 3, 3) =="add")
            $popups_additional[$i++]=$nf_additional;
      }
      closedir($fd_additional);
      if ($i>0){
	    sort($popups_additional);
	    foreach($popups_additional as $popup_additional){
		$popup_additional=substr($popup_additional,0,-4);
		echo"<acronym title='".substr($popup_additional,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/additional/$popup_additional.png' border=0 onClick=\"openPopUp('$popup_additional','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>
   </div>

   <div class="tab-page">
      <h2 class="tab">X-Win32</h2>
    <?php
      //popup icons link autoload
      $component="xwin32";
      $i=0;
      $fd_xwin32=opendir("$path/$appname/popup/component/xwin32/");
      while (false !== ($nf_xwin32= readdir($fd_xwin32))){
          if (substr($nf_xwin32, 3, 6) =="xwin32")
            $popups_xwin32[$i++]=$nf_xwin32;
      }
      closedir($fd_xwin32);
      if ($i>0){
	    sort($popups_xwin32);
	    foreach($popups_xwin32 as $popup_xwin32){
		$popup_xwin32=substr($popup_xwin32,0,-4);
		echo"<acronym title='".substr($popup_xwin32,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/xwin32/$popup_xwin32.png' border=0 onClick=\"openPopUp('$popup_xwin32','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>

   </div>

   <div class="tab-page">
      <h2 class="tab">System</h2>

    <?php
      //popup icons link autoload
      $component="system";
      $i=0;
      $fd_system=opendir("$path/$appname/popup/component/system/");
      while (false !== ($nf_system= readdir($fd_system))){
          if (substr($nf_system, 3, 3) =="sys")
            $popups_system[$i++]=$nf_system;
      }
      closedir($fd_system);
      if ($i>0){
	    sort($popups_system);
	    foreach($popups_system as $popup_system){
		$popup_system=substr($popup_system,0,-4);
		echo"<acronym title='".substr($popup_system,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/system/$popup_system.png' border=0 onClick=\"openPopUp('$popup_system','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>

   </div>

   <div class="tab-page">
      <h2 class="tab">Data Access</h2>

    <?php
      //popup icons link autoload
      $component="dataccess";
      $i=0;
      $fd_dataccess=opendir("$path/$appname/popup/component/dataccess/");
      while (false !== ($nf_dataccess= readdir($fd_dataccess))){
          if (substr($nf_dataccess, 3, 5) =="tdata")
            $popups_dataccess[$i++]=$nf_dataccess;
      }
      closedir($fd_dataccess);
      if ($i>0){
	    sort($popups_dataccess);
	    foreach($popups_dataccess as $popup_dataccess){
		$popup_dataccess=substr($popup_dataccess,0,-4);
		echo"<acronym title='".substr($popup_dataccess,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/dataccess/$popup_dataccess.png' border=0 onClick=\"openPopUp('$popup_dataccess','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>

   </div>

   <div class="tab-page">
      <h2 class="tab">Data Controls</h2>
    <?php
      //popup icons link autoload
      $component="datacontrol";
      $i=0;
      $fd_datacontrol=opendir("$path/$appname/popup/component/datacontrol/");
      while (false !== ($nf_datacontrol= readdir($fd_datacontrol))){
          if (substr($nf_datacontrol, 3, 3) =="tdb")
            $popups_datacontrol[$i++]=$nf_datacontrol;
      }
      closedir($fd_datacontrol);
      if ($i>0){
	    sort($popups_datacontrol);
	    foreach($popups_datacontrol as $popup_datacontrol){
		$popup_datacontrol=substr($popup_datacontrol,0,-4);
		echo"<acronym title='".substr($popup_datacontrol,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/datacontrol/$popup_datacontrol.png' border=0 onClick=\"openPopUp('$popup_datacontrol','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>

   </div>
   <div class="tab-page">
      <h2 class="tab">SQL Commands</h2>
    <hr />
   </div>

   <div class="tab-page">
      <h2 class="tab">Internet</h2>
    <?php
      //popup icons link autoload
      $component="internet";
      $i=0;
      $fd_internet=opendir("$path/$appname/popup/component/internet/");
      while (false !== ($nf_internet= readdir($fd_internet))){
          if (substr($nf_internet, 3, 5) =="thtml")
            $popups_internet[$i++]=$nf_internet;
      }
      closedir($fd_internet);
      if ($i>0){
	    sort($popups_internet);
	    foreach($popups_internet as $popup_internet){
		$popup_internet=substr($popup_internet,0,-4);
		echo"<acronym title='".substr($popup_internet,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/internet/$popup_internet.png' border=0 onClick=\"openPopUp('$popup_internet','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>
   </div>

   <div class="tab-page">
      <h2 class="tab">XML</h2>
    <?php
      //popup icons link autoload
      $component="xml";
      $i=0;
      $fd_xml=opendir("$path/$appname/popup/component/xml/");
      while (false !== ($nf_xml= readdir($fd_xml))){
          if (substr($nf_xml, 3, 4) =="txml")
            $popups_xml[$i++]=$nf_xml;
      }
      closedir($fd_xml);
      if ($i>0){
	    sort($popups_xml);
	    foreach($popups_xml as $popup_xml){
		$popup_xml=substr($popup_xml,0,-4);
		echo"<acronym title='".substr($popup_xml,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/xml/$popup_xml.png' border=0 onClick=\"openPopUp('$popup_xml','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>

   </div>

   <div class="tab-page">
      <h2 class="tab">Dialogs</h2>
    <?php
      //popup icons link autoload
      $component="dialogs";
      $i=0;
      $fd_dialog=opendir("$path/$appname/popup/component/dialogs/");
      while (false !== ($nf_dialog= readdir($fd_dialog))){
          if (substr($nf_dialog, -10) =="dialog.php")
            $popups_dialog[$i++]=$nf_dialog;
      }
      closedir($fd_dialog);
      if ($i>0){
	    sort($popups_dialog);
	    foreach($popups_dialog as $popup_dialog){
		$popup_dialog=substr($popup_dialog,0,-4);
		echo"<acronym title='".substr($popup_dialog,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/dialogs/$popup_dialog.png' border=0 onClick=\"openPopUp('$popup_dialog','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>

   </div>

   <div class="tab-page">
      <h2 class="tab">Servers</h2>
    <?php
      //popup icons link autoload
      $component="server";
      $i=0;
      $fd_server=opendir("$path/$appname/popup/component/server/");
      while (false !== ($nf_server= readdir($fd_server))){
          if (substr($nf_server, -10) =="server.php")
            $popups_server[$i++]=$nf_server;
      }
      closedir($fd_server);
      if ($i>0){
	    sort($popups_server);
	    foreach($popups_server as $popup_server){
		$popup_server=substr($popup_server,0,-4);
		echo"<acronym title='".substr($popup_server,3)."'>
		<input type='image' src='$path/$appname/popup/images/component/server/$popup_server.png' border=0 onClick=\"openPopUp('$popup_server','$component','".theme()."'); \" />
		</acronym>
		";
	    }
	}
    ?>
   </div>

</div>
  <br>
  <br>
  </fieldset>

<?

function makeform($randpath,$nf,$appname){

    echo "<h3>$randpath$nf</h3>\n";

// --------tabs---------------------------------------------------------------------------------------------------------
echo "<script type='text/javascript' src='js/tabs/tabpane.js'></script>";
echo "<link type='text/css' rel='StyleSheet' href='js/tabs/tabpane.css' />";

echo "<div class='tab-pane' id='tab-pane-1'>";

echo   "<div class='tab-page' id='tab-$randpath$nf'>";
echo      "<h2 class='tab' id='code-$randpath$nf'>CODE</h2>";

echo    "File:<b>[</b>$randpath$nf<b>]</b>";
echo    "<hr />";
$file=$randpath.$nf;
//if (substr($nf, -4) != ".inc") {
//echo "<form action='index.php?appname=$appname&op=save&file=$randpath$nf/application.inc' method='post'>";
//} else {
echo "<form name='form-$randpath$nf' action='index.php?appname=$appname&file=$file&op=save' method='post'>";
//}

if (file_exists("extras/codepress/codepress.php")){
//    echo "<input type='hidden' name='myfile' value=''>";

if ((substr($nf, -4) != ".inc") && (substr($nf, -4) != ".php") && (substr($nf, -4) != ".asp") && (substr($nf, -3) != ".c#") && (substr($nf, -4) != ".cpp") && (substr($nf, -4) != ".css") && (substr($nf, -4) != ".pas") && (substr($nf, -4) != ".txt") && (substr($nf, -3) != ".js") && (substr($nf, -5) != ".html") && (substr($nf, -3) != ".py") && (substr($nf, -3) != ".rb") && (substr($nf, -3) != ".pl") && (substr($nf, -5) != ".java")) {
    echo "Questa e' una cartella !!!"; $cartella="on";
} else { $cartella="";
    if (substr($nf, -3) == "asp") { $des="asp";}
    if (substr($nf, -2) == "c#")  { $des="c#"; }
    if (substr($nf, -3) == "cpp") { $des="cpp"; }
    if (substr($nf, -3) == "css") { $des="css"; }
    if (substr($nf, -3) == "pas") { $des="pas"; }
    if (substr($nf, -3) == "txt") { $des="generic"; }
    if (substr($nf, -4) == "html") { $des="html"; }
    if (substr($nf, -4) == "java") { $des="java"; }
    if (substr($nf, -2) == "js") { $des="javascript"; }
    if (substr($nf, -3) == "php") { $des="php"; }
    if (substr($nf, -3) == "inc") { $des="php"; }
    if (substr($nf, -2) == "py") { $des="pyton"; }
    if (substr($nf, -2) == "rb") { $des="ruby"; }
    if (substr($nf, -2) == "pl") { $des="pl"; }
//echo "linguaggio: ".$des."<br>";
    echo "<input type='hidden' name='myfile-$randpath$nf' value=''>";
    echo "<iframe id='codepress-$randpath$nf' name='codepress-$randpath$nf' src='extras/codepress/codepress.php?action=edit&file=$randpath$nf&language=$des' width='100%' height='400'></iframe>";
    echo "<p align='right'><input type='image' name='save' src='applications/$appname/_images/save.png' onClick='myfile-$randpath$nf.value = CodePress.getCode(); alert(myfile-$randpath$nf.value)';></p>";
//    echo "<p align='right'><input type='submit' name='save' value='save code' onClick='myfile.value = CodePress.getCode();alert(myfile.value)';'></p>";
}
}
echo "</form>";

if ($cartella=="on") {
    if ($nf == "asp") { $des=".asp"; }
    if ($nf == "c#") { $des=".c#"; }
    if ($nf == "cpp") { $des=".cpp"; }
    if ($nf == "css") { $des=".css"; }
    if ($nf == "delphi") { $des=".pas"; }
    if ($nf == "generic") { $des=".txt"; }
    if ($nf == "html") { $des=".html"; }
    if ($nf == "java") { $des=".java"; }
    if ($nf == "javascript") { $des=".js"; }
    if ($nf == "php") { $des=".php"; }
    if ($nf == "pyton") { $des=".py"; }
    if ($nf == "ruby") { $des=".rb"; }
    if ($nf == "text") { $des=".txt"; }
    if ($nf == "pascal") { $des=".pas"; }
    if ($nf == "perl") { $des=".pl"; }
	echo "</br>";
	echo "<form name='newdir' action='index.php?appname=$appname&app-path=datas/sources/$nf&name=&op=creanuovadir' method='post'>\n";
	echo "<input type='text' name='newfile' value='nomecartella'>\n";
    echo "<input type='image' src='applications/$appname/_images/add_dir.png' onclick='' alt='Crea Nuova Cartella'/>";
//	echo "<input type='submit' value='crea nuova cartella'>\n";
	echo "</form>\n";

	echo "</br>";
	echo "<form name='deldir' action='index.php?appname=$appname&app-path=datas/sources/$nf&name=&op=eliminadir' method='post'>\n";
	echo "<input type='text' name='newfile' value='nomecartella'>\n";
    echo "<input type='image' src='applications/$appname/_images/del_dir.png' onclick='' alt='Elimina Cartella'/>";
//	echo "<input type='submit' value='elimina cartella'>\n";
	echo "</form>\n";

	echo "</br>";
	echo "<form name='newapp' action='index.php?appname=$appname&app-path=datas/sources/$nf&name=&op=creanuovofile' method='post'>\n";
	echo "<input type='text' name='newfile' value='nomefile$des'>\n";
    echo "<input type='image' src='applications/$appname/_images/vcs_add.png' onclick='' alt='Crea Nuovo File'/>";
//	echo "<input type='submit' value='nuovofile'>\n";
	echo "</form>\n";

	echo "</br>";
	echo "<form name='delapp' action='index.php?appname=$appname&app-path=datas/sources/$nf&name=&op=cancellafile' method='post'>\n";
	echo "<input type='text' name='delfile' value='nomefile$des'>\n";
    echo "<input type='image' src='applications/$appname/_images/vcs_remove.png' onclick='' alt='Elimina File'/>";
//	echo "<input type='submit' value='cancella file'>\n";
	echo "</form>\n";

}

   echo "</div>";

echo   "<div class='tab-page' id='FCK-$randpath$nf'>";
echo      "<h2 class='tab' id='FCKtab-$randpath$nf'>V-Form</h2>";

if (file_exists("extras/FCKeditor/fckeditor.php")){
//  include("extras/FCKeditor/fckeditor.php");

  $sBasePath ="extras/FCKeditor/" ;

  $oFCKeditor = new FCKeditor('editor') ;
  $oFCKeditor->BasePath	= $sBasePath;
  $oFCKeditor->Height= 400;
  $oFCKeditor->Value	= @join(@file($file));
  $oFCKeditor->Create() ;
}

echo "</div>";

   echo "</div>";
// ---------------------------------------------------------------------------------------------------------------------
}


global $tree,$tree_i;
$tree_i=1;

function dirconfig($randpath,$myparent,$appname){
    global $tree,$tree_i;
    //$fd=glob($randpath."*");
    $fdh=opendir($randpath);
    while (false !== ($nf= readdir($fdh))){
	if ($nf[0]!='.' )
	$fd[$i++]=$nf;
    }
    closedir($fdh);

    if (count($fd)){
	sort($fd);
	foreach($fd as $nf){
	    $nf=basename($nf);
	    if ($nf[0]!='.' ){
		if (is_dir($randpath.$nf)){
		    if (file_exists($randpath.$nf)){
			$tree[$tree_i++]=$nf;
			echo "<script>tree.insertNewItem($myparent,$tree_i,\"$randpath$nf\",0,0,0,0,\"SELECT\");</script>\n ";
			echo"<div id='$tree_i' style=\"display:none;border:2;\" >\n";
			makeform($randpath,$nf,$appname);
			echo "</div>\n";
			dirconfig($randpath.$nf."/",$tree_i,$appname);
		    }
		}
		else{
		    if ($nf!=""){
			$tree[$tree_i++]=$nf;
			echo "<script>tree.insertNewItem($myparent,$tree_i,\".$randpath$nf\",0,0,0,0,\"SELECT\");</script>\n ";
			echo "<div id='$tree_i' style=\"display:none;border:2;\" >\n";
			makeform($randpath,$nf,$appname);
			echo "</div>\n";
		    }
		}
	    }
	}
    }
echo "<script>tree.closeAllItems(0);</script>\n";
}

?>
<?php if (admin_isadmin()) {
        admin_writelog(_ADMIN_PREFERENCE);
?>
    <p>


<style>
.fold
{
	border: 1px solid #808080;
}

</style>

<style>
	body {font-size:12px}
	.{font-family:arial;font-size:12px}
	h1 {cursor:hand;font-size:16px;margin-left:10px;line-height:10px}
	xmp {color:green;font-size:12px;margin:0px;font-family:courier;background-color:#e6e6fa;padding:2px}
</style>

<input type='image' src='themes/<?=theme();?>/images/user-screen2-hilite.gif' border='0' alt='All Screen View (On/Off)' onclick="javascript:spazio();" />
<input type='image' src='applications/<?=$appname;?>/_images/menu_view_forms.png' alt='Component ToolBar View (On/Off)' onclick="javascript:toolbar_inout();" />
<input type='image' src='applications/<?=$appname;?>/_images/fold.gif' alt='Files Tree View (On/Off)' onclick="javascript:inout();" />
<input type='image' src='applications/<?=$appname;?>/_images/menu_run.png' alt='Run Current Program' onclick="javascript: tonclick(runfile); run_program(runfile);" />
<input type='image' src='applications/<?=$appname;?>/_images/favicon.ico' alt='Object Inspector (On/Off)' onclick="javascript:inspectorinout();" />
<input type='image' src='applications/<?=$appname;?>/_images/ongoing.gif' alt='Object List View (On/Off)' onclick="javascript:objecttreeviewinout();" />

	<link rel="STYLESHEET" type="text/css" href="../css/dhtmlXTree.css">
	<script  src="js/dhtmlxTree/js/dhtmlXCommon.js"></script>
	<script  src="js/dhtmlxTree/js/dhtmlXTree.js"></script>

	<table border='0'>
		<tr>
			<td valign="top" >

  <fieldset id='objecttreeview' >
    <legend> Object List View </legend>
    <br>
    <div id='objecttreeviewinout' style="width: 250; height: 180;background-color:#f5f5f5;border :0px solid Silver;; overflow:auto;">
        <h3>Object List View</h3>
    </div>
    <br>
  </fieldset>

  <fieldset id='objectinspector' >
    <legend> Object Inspector </legend>
    <br>
    <div id='inspector' style="width: 250; height: 480;background-color:#f5f5f5;border :0px solid Silver;; overflow:auto;">
        <h3>Object Inspector</h3>
    </div>
    <br>
  </fieldset>

  <fieldset id='treebox' >
  <legend> Tree Files Box </legend>
  <br>
                <div id="treeboxbox_tree" style="width: 250; height: 480;background-color:#f5f5f5;border :0px solid Silver;; overflow:auto;"></div>
    <br>
  </fieldset>
			</td>
			<td valign="top" width="100%">

</p>
	<script>
			tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
			tree.setImagePath("js/dhtmlxTree/imgs/");

            function tonclick(id){
                var ob;
                var runfile;
                for (i=0;i<99;i++){
                    ob=document.getElementById(i);
                    if (ob)ob.style.display="none";
                }

                ob=document.getElementById(id);
                if (ob)ob.style.display="inline";
                //alert (id);
                //runfile = id;
                runfile=tree.getSelectedItemText();
                //alert(runfile);
                return runfile;

            }
	       tree.setOnClickHandler(tonclick);
           
	</script>

<?php

	//$lista=glob("applications/$appname/template/*");
	$fd=opendir("applications/$appname/template/");
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		$lista[$i++]=$nf;
	}
	closedir($fd);
	if (count($lista))sort($lista);

	echo "<script>tree.insertNewItem(0,1,\"sources\",0,0,0,0,\"SELECT\");</script>\n ";
	echo "<div id='1' style=\"display:none;border:2;\" >\n";
//	echo "<h3 >add application</h3>";
//	echo "<form name='newapp' action='index.php?appname=$appname&app-path=applications&name=&op=install' method='post'>\n";
//	echo "<select name='addnew'>\n";
//	foreach($lista as $elemento)
//	    echo "<option value='$elemento'>".basename($elemento)."</option>\n";
//	echo "</select>\n";
//	echo "<input type='submit' value='install'>\n";
//	echo "</form>\n";
//	echo "</br>";
//	echo "<form name='newapp' action='index.php?appname=$appname&app-path=datas/sources&name=&op=creanuovofile' method='post'>\n";
//	echo "<input type='text' name='newfile' value='nomefile.des'>\n";
//	echo "<input type='submit' value='nuovofile'>\n";
//	echo "</form>\n";
	echo "</div>\n";
	echo "<script>tonclick(0);</script>";

    if (!file_exists("datas/sources")) {mkdir("datas/sources",0755);}
    if (!file_exists("datas/sources/php")) {mkdir("datas/sources/php",0755);}
    if (!file_exists("datas/sources/asp")) {mkdir("datas/sources/asp",0755);}
    if (!file_exists("datas/sources/cpp")) {mkdir("datas/sources/cpp",0755);}
    if (!file_exists("datas/sources/c#")) {mkdir("datas/sources/c#",0755);}
    if (!file_exists("datas/sources/css")) {mkdir("datas/sources/css",0755);}
    if (!file_exists("datas/sources/delphi")) {mkdir("datas/sources/delphi",0755);}
    if (!file_exists("datas/sources/html")) {mkdir("datas/sources/html",0755);}
    if (!file_exists("datas/sources/javascript")) {mkdir("datas/sources/javascript",0755);}
    if (!file_exists("datas/sources/java")) {mkdir("datas/sources/java",0755);}
    if (!file_exists("datas/sources/perl")) {mkdir("datas/sources/perl",0755);}
    if (!file_exists("datas/sources/pyton")) {mkdir("datas/sources/pyton",0755);}
    if (!file_exists("datas/sources/ruby")) {mkdir("datas/sources/ruby",0755);}
    if (!file_exists("datas/sources/text")) {mkdir("datas/sources/text",0755);}
    if (!file_exists("datas/sources/generic")) {mkdir("datas/sources/generic",0755);}
    if (!file_exists("datas/sources/pascal")) {mkdir("datas/sources/pascal",0755);}
	dirconfig("datas/sources/",1,$appname);


	$op=$_GET['op'];

	if ($op=="change"){
	    $name=$_GET['name'];
	    $app_path=$_POST['app-path'];
	    $app_newpath=$_POST['app-newpath'];

	    $hidden=$_POST['hidden'];
	    $order=$_POST['order'];
	    $application=$_POST['application'];

	    echo "OP:$op<br/>\n\n";
	    echo "path:$app_path<br/>\n";
	    echo "newpath:$app_newpath<br/>\n";
	    echo "applicazione:$application<br/>\n";
	    echo "nascosto:$hidden<br/>\n";
	    echo "ordine:$order<br/>\n";
	    echo "file:$name<br/>\n";

	    if ($hidden==''){
		if ($order==''){
		    $newname=$application;
		}
		else{
		    $newname=$order."_".$application;
		}
	    }
	    else{
		if ($order==''){
		    $newname="_".$application;
		}
		else{
		    $newname="_".$order."_".$application;
		}
	    }
	    echo "nuovo nome:$newname<br/>\n";
	    rename("$app_path/$name","$app_newpath/$newname");
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

	if ($op=="del"){
	    $name=$_GET['name'];
	    $app_path=$_GET['app-path'];
	    echo "".$app_path.$name." eliminata";
	    deltree("".$app_path.$name);
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

	if ($op=="install"){
	    $name=$_GET['name'];
	    $app_path=$_GET['app-path'];
	    $addnew=$_POST['addnew'];
	    echo "applicazione $app_path.$name/".basename($addnew)." installata<br/>" ;
	    if (is_dir($addnew))
		copytree("$addnew",$app_path.$name."/".basename($addnew));
	    else
		copy("$addnew",$app_path.$name."/".basename($addnew));
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

	if ($op=="save"){
//        $myfile=$_POST['myfile'];
//        $file=$_GET['file'];
//        echo $file." salvato<br>";
//        echo $myfile."<br>";
//        $fp=fopen($file,"w");
//           fwrite($fp, $myfile);
//        fclose($fp);
        echo "Operazione di salvataggio riuscita !!!<br>";
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

	if ($op=="creanuovofile"){
	    $name=$_POST['newfile'];
	    $app_path=$_GET['app-path'];
        $nf=$_GET['nf'];
        $fp=fopen("$app_path/$nf$name","w");
           fwrite($fp, "<-- *** Created with FW-IDE *** -->\n");
        fclose($fp);
        echo "Nuovo file creato !!!<br>";
        echo "path: ".$app_path."<br>";
        echo "nome file: ".$name."<br>";
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

	if ($op=="cancellafile"){
	    $name=$_POST['delfile'];
	    $app_path=$_GET['app-path'];
        $nf=$_GET['nf'];
        unlink("$app_path/$nf$name");
	    echo "$app_path/$nf$name eliminato !!!";
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}



	if ($op=="creanuovadir"){
	    $name=$_POST['newfile'];
	    $app_path=$_GET['app-path'];
        $nf=$_GET['nf'];
        if (!file_exists("$app_path/$name")) {mkdir("$app_path/$name",0755);}
        echo "Nuova cartella creata !!!<br>";
        echo "path: ".$app_path."<br>";
        echo "nome file: ".$name."<br>";
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

	if ($op=="eliminadir"){
	    $name=$_POST['newfile'];
	    $app_path=$_GET['app-path'];
        $nf=$_GET['nf'];
        rmdir("$app_path/$name");
        echo "Cartella eliminata !!!<br>";
        echo "path: ".$app_path."<br>";
        echo "nome file: ".$name."<br>";
	    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
	}

?>

	    </td>
	</tr>
    </table>
    <?php
    }else{
    ?>
	<p><?=_ADMINISTRATION_PRIVILEGE_REQUESTED?> </p>
    <?php } ?>
<hr/>

<script>
// settaggio per inspector ad avvio procedura
    document.getElementById('inspector').style.display='none';
    document.getElementById('objectinspector').style.display='none';
    document.getElementById('objecttreeviewinout').style.display='none';
    document.getElementById("objecttreeview").style.display='none';
</script>

